import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

const okIcon  = Icon(Icons.mood, color: Colors.green, size: 26,);
const errIcon = Icon(Icons.mood_bad, color: Colors.red, size: 26,);

void toast(BuildContext context, {sec=2, ok=true, required String msg}) async {
  //获取OverlayState
  OverlayState? overlayState = Overlay.of(context);
  //创建OverlayEntry
  OverlayEntry _overlayEntry = OverlayEntry(
      builder: (BuildContext context) => Positioned(
        right: 10,
        top: 70,
        child: Opacity(
            opacity: .7,
            child: ClipRRect(
                borderRadius: BorderRadius.circular(3.0),
                child: Container(
                    color: Colors.lightBlueAccent,
                    padding: const EdgeInsets.only(left: 10, top: 5, bottom: 5, right: 10),
                    child:Row(children:[
                      ok ? okIcon : errIcon,
                      const VerticalDivider(width: 10,),
                      Text(msg, style: Theme.of(context).textTheme.bodyText1, overflow: TextOverflow.ellipsis,),
                    ])))),
      ));

  //显示到屏幕上。
  overlayState?.insert(_overlayEntry);

  //等待2秒
  await Future.delayed(Duration(seconds: sec));
  //移除
  _overlayEntry.remove();
}


void showMyCupertinoDialog(BuildContext context) {
  showCupertinoDialog(
      context: context,
      builder: (context) {
        return const CupertinoActivityIndicator(radius: 20);
      }
  );
}

Widget VD = Container(
  margin: const EdgeInsets.only(left: 10, right: 10, top: 2, bottom: 2),
  child: const VerticalDivider(width: 1),
);
